<?php
/**
 * 登录登出
 * Author: lee wei
 * Date: 2021/12/7
 */
declare (strict_types=1);

namespace app\admin\controller;

use app\admin\service\LoginService;


use app\Common\Coderesponse;
use think\Response;

class Login extends Base {

    public function index()
    {
        $username = $this->request->post('username');
        $password = $this->request->post('password');

        if (!$username) {
            return $this->buildFailed(Coderesponse::LOGIN_ERROR, '缺少用户名!');
        }
        if (!$password) {
            return $this->buildFailed(Coderesponse::LOGIN_ERROR, '缺少密码!');
        }

        $result =  LoginService::getInstance()->login($username, $password);

        if(!$result)
            return $this->buildFailed(Coderesponse::LOGIN_ERROR, $result->getError());

        $data = [
            'token' => ''
        ];

        return $this->buildSuccess($data, Coderesponse::SUCCESS);
    }

}